<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let p = new Promise((resolve, reject) => {
            let count = Math.floor(Math.random() * 10);

            setTimeout(() => {
                console.log(count);
                if (count >= 3) {
                    resolve("success")


                } else {
                    reject("fail");
                }
            }, 1000);
        });

        /*   p.then((res) => {
              console.log(res)
              return undefined
          })
              .then(res => {
                  console.log(res)
              })
              .catch(err => {
                  console.log(err)
              }) */

        p.then(res1 => {
            console.log(res1)
            // return Promise.resolve('success ~! second')
            // return Promise.reject('fail ~! second')
            // throw new Error('new fail')

            /* 
            return Promise.resolve('')
            return Promise.reject('')
            throw new Error('')
            return Promise.resolve('')
            return Promise.reject('')
            throw new Error('')
            
            */
        }).then(res2 => {
            console.log(res2)
        }).catch(err => {
            console.log(err)
        })
    </script>
</body>

</html>